package com.ysd.servlet.admin;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.ysd.dao.impl.GongSiXinXiBiaoDaoImpl;
import com.ysd.entity.GongSiXinXiBiao;
import com.ysd.util.BaseServlet;
import com.ysd.util.Result;

public class AdminGongSiBiaoServlet extends BaseServlet {

	/**
	 * 查询所有公司信息 localhost:8080/qiuxieshangcheng/adminGongSiBiao?reqName=getGSB
	 */
	public void getGSB(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		GongSiXinXiBiaoDaoImpl gsDao = new GongSiXinXiBiaoDaoImpl();
		List<GongSiXinXiBiao> gsList = gsDao.getGongSiXinXiBiaoCeShi();

		// 发送Ajax请求 服务器基本返回json格式字符串
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();

		Gson gson = new Gson();
		String res = gson.toJson(gsList);
		out.print(res);

		out.flush();
		out.close();

	}

	/**
	 * 回显公司信息 localhost:8080/qiuxieshangcheng/adminGongSiBiao?reqName=getGSB1
	 */
	public void getGSB1(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 发送Ajax请求 服务器基本返回json格式字符串
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		GongSiXinXiBiaoDaoImpl gsDao = new GongSiXinXiBiaoDaoImpl();
		int ID = Integer.parseInt(request.getParameter("ID"));
		GongSiXinXiBiao gsb=   gsDao.getGongSiBiao(ID);
		Gson gson = new Gson();
		String res = gson.toJson(gsb);
		out.print(res);
		out.flush();
		out.close();

	}
	
	/**
	 * 修改公司信息 localhost:8080/qiuxieshangcheng/adminGongSiBiao?reqName=updateGSB
	 */
	public void updateGSB(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 发送Ajax请求 服务器基本返回json格式字符串
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		GongSiXinXiBiaoDaoImpl gsDao = new GongSiXinXiBiaoDaoImpl();
		int id = Integer.parseInt(request.getParameter("gsId"));
		String  loGo= request.getParameter("gsLoGo");
		String  name= request.getParameter("gsName");
		String  wangZhi= request.getParameter("gsWZ");
		
		String  gongSiJieShao= request.getParameter("gsJS");
		String  qiYeWenHua= request.getParameter("gsWH");
		String  gongSiDianHua= request.getParameter("gsPhone");
		String  email= request.getParameter("gsEmail");
		String  gongSiDiZhi= request.getParameter("gsDiZhi");
		
		

		GongSiXinXiBiao gsb = new GongSiXinXiBiao(id, loGo, name, wangZhi, gongSiJieShao, qiYeWenHua, gongSiDianHua, email, gongSiDiZhi);
		int n = gsDao.updateGSB(gsb);
		if (n>0) {
			out.print(Result.toClient(true, "修改成功",""));
		} else {
			out.print(Result.toClient(false, "修改失败",""));
		}
		
		out.flush();
		out.close();

	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

}
